# -*- coding: utf-8-unix; fill-column: 95; -*-

###############################################################################################
#
# This file is part of Escapade Trip Planner, a social web application for creating and
# sharing motorcycle roadmaps.
#
# Copyright © 2011, Pierre-François Gomez <pef.gomez@gmail.com>
#
# Escapade Trip Planner is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software Foundation, either
# version 3 of the License, or (at your option) any later version.
#
# Escapade Trip Planner is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with Escapade Trip
# Planner. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################################

from collections import MutableSequence

#class Roadmap(MutableSequence):
class Roadmap:

    __allowed_attributes__ = ('id', 'name', 'description', 'legs')
    def __init__(self, *p_args, **p_kwargs):
        for k, v in p_kwargs.items():
            if k not in self.__class__.__allowed_attributes__:
                raise TypeError("Invalid keyword argument %s" % k)
            setattr(self, k, v)

    def read(self):
        return({'id': getattr(self, 'id', None),
                'name': getattr(self, 'name', None),
                'description': getattr(self, 'description', None),
                'legs': [leg for leg in getattr(self, 'legs', [])]})

    def summary(self):
        return({'id': getattr(self, 'id', None),
                'name': getattr(self, 'name', None),
                'description': getattr(self, 'description', None),
                'leaf': True})

# Méthodes héritées de MutableSequence :
# __contains__
# __delitem__
# __getitem__
# __iadd__
# __iter__
# __len__
# __reversed__
# __setitem__
# append
# count
# extend
# index
# insert
# remove
# reverse
# pop
#
# TODO : compléter ce qui manque :
#        - notion de draft (apply/discard)
